package www.openteam.com.adapter.PrdctnMngmnt;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import www.openteam.com.R;
import www.openteam.com.bean.SRCKProductMaterial;

/**
 * Created by Administrator on 2019-06-21.
 */

public class SRCKManuMaterialAdp extends RecyclerView.Adapter<SRCKManuMaterialAdp.ViewHolder> {
    Context context;
    List<SRCKProductMaterial.DataBeanX.DataBean> dataBeanList = new ArrayList<>();
    SRCKMaterialClickBack srckMaterialClickBack;
    double mClickTime = 0;


    public void setSrckPlanClickBack(SRCKMaterialClickBack srckMaterialClickBack) {
        this.srckMaterialClickBack = srckMaterialClickBack;
    }

    public SRCKManuMaterialAdp(Context context, List<SRCKProductMaterial.DataBeanX.DataBean> dataBeanList) {
        this.context = context;
        this.dataBeanList = dataBeanList;
    }

    public interface SRCKMaterialClickBack {
        void postdata(SRCKProductMaterial.DataBeanX.DataBean dataBean);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_srck_material, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final SRCKProductMaterial.DataBeanX.DataBean dataBean = dataBeanList.get(position);
        holder.srckMaterialSort.setText(dataBean.getType_name());
        holder.srckMaterialClassify.setText(dataBean.getTypeNameM());
        holder.srckMaterialStockNum.setText(dataBean.getCode());
        holder.srckMaterialStockName.setText(dataBean.getName());
        holder.srckMaterialSandard.setText(dataBean.getSpecs());
        holder.srckMaterialPUnit.setText(dataBean.getUnit());
        holder.srckMaterialLine.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (System.currentTimeMillis() - mClickTime <600) {
                    if (null!=srckMaterialClickBack){
                        srckMaterialClickBack.postdata(dataBean);
                    }
                } else {
                    mClickTime = System.currentTimeMillis();
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return dataBeanList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.srck_material_sort)
        TextView srckMaterialSort;
        @Bind(R.id.srck_material_classify)
        TextView srckMaterialClassify;
        @Bind(R.id.srck_material_stockNum)
        TextView srckMaterialStockNum;
        @Bind(R.id.srck_material_stockName)
        TextView srckMaterialStockName;
        @Bind(R.id.srck_material_sandard)
        TextView srckMaterialSandard;
        @Bind(R.id.srck_material_pUnit)
        TextView srckMaterialPUnit;
        @Bind(R.id.srck_material_line)
        LinearLayout srckMaterialLine;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
